#ifndef GRAPH_H
#define GRAPH_H
#include "D3DApp.h"
#include "GameObject.h"
#include "MainState.h"
#include <vector>
#include <list>
#include <algorithm>


class GraphNode
{
public:
	GraphNode();
	GraphNode(D3DXVECTOR2 p, int i);
	GraphNode(D3DXVECTOR2 p);
	
	void SetPos(D3DXVECTOR2 p);
	void SetIndex(int i);
	void Activate();
	void Deactivate();

	D3DXVECTOR2 GetPos() const;
	int GetIndex() const;
	bool GetActive();

private:
	D3DXVECTOR2 m_Pos;
	int m_Index;
	bool m_Active;
};

class GraphEdge
{
public:
	
	GraphEdge();
	GraphEdge(int f, int t);
	GraphEdge(int f, int t, float c);
	
	int GetFrom();
	int GetTo();
	float GetCost();
	void SetCost(float c);

	bool operator==(GraphEdge rhs)
	{
		bool f;
		if(m_From==rhs.m_From)
		{
			f=true;
		}
		else
		{
			f=false;
		}

		bool t;
		if(m_To==rhs.m_To)
		{
			t=true;
		}
		else
		{
			t=false;
		}

		if(t==true && f==true)
		{
			return true;
		}
		return false;
	}
	bool operator!=(GraphEdge rhs)
	{
		bool f;
		if(m_From!=rhs.m_From)
		{
			f=true;
		}
		else
		{
			f=false;
		}

		bool t;
		if(m_To!=rhs.m_To)
		{
			t=true;
		}
		else
		{
			t=false;
		}

		if(t==true && f==true)
		{
			return true;
		}
		return false;
	}

private:
	int m_From;
	int m_To;
	float m_Cost;

};
class Graph : public GameObject
{
public:
	Graph();
	~Graph(){}

	int AddNode(GraphNode G);
	void AddEdge(GraphEdge E);

	void RemoveNode(int i);

	GraphNode* GetNode(int i);
	GraphEdge GetEdge(int from, int to);
	std::list<GraphEdge> GetEdgeList(int i);

	int GetNumNodes();
	int GetNumActiveNodes();
	int GetNumEdges();

	int GetNodeID(D3DXVECTOR2 d);
	D3DXVECTOR2 GetNodePos(int id);

	void Clear();

	bool IsEmpty();
	bool IsEdgePresent(int from, int to);

	void Render();

private:
	std::vector<GraphNode> m_Nodes;
	std::vector<std::list<GraphEdge>> m_Edges;
	std::vector<GameObject*> m_NodeGOs;
	int m_NextIndex;
	int m_ActiveNodes;
};



#endif